package com.gaohe.web.controller.dcp;

import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.core.page.TableDataInfo;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.dcp.domain.DcpHospital;
import com.gaohe.dcp.service.IDcpHospitalService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医院信息Controller
 *
 * @author ruoyi
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/dcp/hospital")
public class  DcpHospitalController extends BaseController
{
    @Autowired
    private IDcpHospitalService dcpHospitalService;

    /**
     * 查询医院信息列表
     */
//    @PreAuthorize("@ss.hasPermi('dcp:hospital:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcpHospital dcpHospital)
    {
        startPage();
        List<DcpHospital> list = dcpHospitalService.selectDcpHospitalList(dcpHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院信息列表
     */
    @PreAuthorize("@ss.hasPermi('dcp:hospital:export')")
    @Log(title = "医院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcpHospital dcpHospital)
    {
        List<DcpHospital> list = dcpHospitalService.selectDcpHospitalList(dcpHospital);
        ExcelUtil<DcpHospital> util = new ExcelUtil<DcpHospital>(DcpHospital.class);
        util.exportExcel(response, list, "医院信息数据");
    }

    /**
     * 获取医院信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('dcp:hospital:query')")
    @GetMapping(value = "/{hospitalId}")
    public AjaxResult getInfo(@PathVariable("hospitalId") Long hospitalId)
    {
        return success(dcpHospitalService.selectDcpHospitalByHospitalId(hospitalId));
    }

    /**
     * 新增医院信息
     */
    @PreAuthorize("@ss.hasPermi('dcp:hospital:add')")
    @Log(title = "医院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcpHospital dcpHospital)
    {
        return toAjax(dcpHospitalService.insertDcpHospital(dcpHospital));
    }

    /**
     * 修改医院信息
     */
    @PreAuthorize("@ss.hasPermi('dcp:hospital:edit')")
    @Log(title = "医院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcpHospital dcpHospital)
    {
        return toAjax(dcpHospitalService.updateDcpHospital(dcpHospital));
    }

    /**
     * 删除医院信息
     */
    @PreAuthorize("@ss.hasPermi('dcp:hospital:remove')")
    @Log(title = "医院信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hospitalIds}")
    public AjaxResult remove(@PathVariable Long[] hospitalIds)
    {
        return toAjax(dcpHospitalService.deleteDcpHospitalByHospitalIds(hospitalIds));
    }
}
